<!--
 * @Description: 
 * @Author: ZachGmy
 * @Date: 2022-08-25 16:52:05
 * @LastEditors: HeAo
 * @LastEditTime: 2022-08-27 09:29:15
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button onclick="toLogin()">登录</button>
  <script>
    // http://121.4.83.32:7004/user/login
    function toLogin() {
      var request = new XMLHttpRequest()
      request.open('post', 'http://121.4.83.32:7004/user/login')
      // 配置参数
      var params = {
        username: 'admin1',
        password: '123321'
      }
      // 设置请求头
      request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
      // JSON.stringify — js对象转为json对象
      request.send(JSON.stringify(params))
      request.onreadystatechange = function () {
        if (request.readyState === 4 && request.status === 200) {
          console.log(request.responseText);
        }
      }
    }
  </script>
</body>

</html>